package com.etc.dao;

import com.etc.entity.Cinema;
import com.etc.entity.Movie;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.List;

@Repository
public interface MovieDao extends JpaRepository<Movie, Integer>, JpaSpecificationExecutor<Movie>, Serializable {
    /*
    按评分大到小排序 正在上映的电影
     */
    List<Movie> findByMstatusOrderByMgradeDesc(Integer mstatus);

    /*
按评分小到大排序 正在上映的电影
 */
    List<Movie> findByMstatusOrderByMgradeAsc(Integer mstatus);


    /*
    根据电影名模糊查询
     */
    @Query("select m from  Movie m where m.mname like %?1%")
    Page<Movie> findByLike(String query, Pageable pageable);

    /*
显示 即将上映的电影
 */
    @Query(nativeQuery = true, value = "select * FROM Movie m where m.mreleasedtime like'上映时间2019-%' ORDER BY m.mreleasedtime ASC limit 5")
    List<Movie> listRecentMovie();

    /*
    显示正在上映的电影
     */
    List<Movie> findByMreleasedtimeContaining(String content);

    Movie findByMname(String mname);

    /**
     * dzq
     * @param name   模糊查詢  電影名
     * @return   Movie集合
     */
    @Query(nativeQuery = true, value = "SELECT * from movie where mname like %?1% ORDER BY  mstatus  ASC  LIMIT 0,20")
    List<Movie> FindMovieByNameForSerach(String name);
}